﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace WinHBM.Core.Net.Sockets.Cmd
{
    public abstract class SocketCmd
    {

        public static string CMD_WINDOW_MINSIZE = "CMD_WINDOW_MINSIZE";
        public static string CMD_WINDOW_EXIT = "CMD_WINDOW_EXIT";
        public static string CMD_LOG = "CMD_LOG";
        public static string CMD_LOGIN = "CMD_LOGIN";
        public static string CMD_LOGOUT = "CMD_LOGOUT";
        public static string CMD_GETUSERINFO = "CMD_GETUSERINFO";
        public static string CMD_GETBARCODE = "CMD_GETBARCODE";
        public static string CMD_GETFLOWERRANK = "CMD_GETFLOWERRANK";
        public static string CMD_NETWORKCONNECT = "CMD_NETWORKCONNECT";
        //软键盘
        public static string CMD_SOFT_KB_OPEN = "CMD_SOFT_KB_OPEN";
        public static string CMD_SOFT_KB_CLOSE = "CMD_SOFT_KB_CLOSE";
        //蓝牙相关
        public static string CMD_BLUETOOTH_BIND = "CMD_BLUETOOTH_BIND";                  //绑定
        public static string CMD_BLUETOOTH_UNBIND = "CMD_BLUETOOTH_UNBIND";              //解绑
        public static string CMD_BLUETOOTH_CONNECT = "CMD_BLUETOOTH_CONNECT";            //连接
        public static string CMD_BLUETOOTH_DISCOVERY = "CMD_BLUETOOTH_DISCOVERY";        //扫描
        public static string CMD_BLUETOOTH_DATA = "CMD_BLUETOOTH_DATA";                  //指令通信(读卡，写卡...等)
        public static string CMD_BLUETOOTH_DISCONNECT = "CMD_BLUETOOTH_DISCONNECT";      //断开连接
        public static string CMD_BLUETOOTH_ONLINE = "CMD_BLUETOOTH_ONLINE";              //打开在线收红花模式
        public static string CMD_BLUETOOTH_OFFLINE = "CMD_BLUETOOTH_OFFLINE";            //关闭在线收红花模式
        public static string CMD_BLUETOOTH_ONLINE_CONNECTFAILED = "CONNECTFAILED";              //在线连接中通信断开
        public static string CMD_BLUETOOTH_ONLINE_CONNECTSUCCESS = "CONNECTSUCCESS";            //在线连接中通信断开后重连成功

        public static string CMD_BABY_COUNT = "CMD_BABY_COUNT";

        public static string CMD_TEST_LOGIN = "CMD_TEST_LOGIN";

        private static JObject successObj = JObject.Parse(@"{'errcode':0,'message':'success'}");

        public JObject SUCCESS { get { return successObj; } }



        public JObject wrapCmd(string cmd, JObject orig)
        {
            return wrapCmd(cmd, "", orig);
        }


        public JObject wrapCmd(string cmd, string error)
        {
            return wrapCmd(cmd, error, null);
        }

        public JObject wrapCmd(string cmd,string error,JObject orig)
        {
            JObject obj = new JObject();
            obj["cmd"] = cmd;
            obj["error"] = error;
            if(orig != null)
            {
                obj["data"] = orig;
            }
            return obj;
        }


        public abstract void executeCmd(JObject request,FlashSocketServer socket);
    }
}
